package com.csd.fragment;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.csd.activity.R;
import com.csd.adapter.ListSelectAdapter;
import com.csd.bean.Car;
import com.csd.view.CarTypePopupwindow;
import com.csd.view.CsdPopupwindow;
import com.csd.view.TimePopupwindow;

public class ListSelectFragment extends Fragment implements OnClickListener{

	private View v;
	private ListView listView;
	private List<Car> list;
	private ListSelectAdapter adapter;
	private LinearLayout ll_take,ll_return,ll_cartype,ll_address;
	private String[] strPurpose = {"接送客户","接送领导","出差","其它"};
	private String str[] = {"天山路641号慧谷白猫科技园","中山西路139号停车场","张杨路1307号"};
	private TextView tv_take,tv_return,tv_cartype,tv_address;
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		v = inflater.inflate(R.layout.fragment_listselect, null);
		initView();
		return v;
	}
	private void initView() {
		// TODO Auto-generated method stub
		listView = (ListView) v.findViewById(R.id.lookup_list);
		list = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			Car car = new Car();
			car.setImg(R.drawable.u103);
			car.setCarBrand("雪佛兰科鲁兹");
			car.setVariator("自排");
			car.setRow(3);
			car.setSeat(5);
			list.add(car);
		}
		adapter = new ListSelectAdapter(list, getActivity());
		listView.setAdapter(adapter);
		ll_take = (LinearLayout) v.findViewById(R.id.ll_taketext);
		ll_address = (LinearLayout) v.findViewById(R.id.ll_addresstext);
		ll_cartype = (LinearLayout) v.findViewById(R.id.ll_carTypetext);
		ll_take.setOnClickListener(this);
		ll_address.setOnClickListener(this);
		ll_cartype.setOnClickListener(this);
		tv_take = (TextView) v.findViewById(R.id.taketime);
		tv_return = (TextView) v.findViewById(R.id.returntime);
		tv_cartype = (TextView) v.findViewById(R.id.cartype);
		tv_address = (TextView) v.findViewById(R.id.address);
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ll_taketext:
			TimePopupwindow takeTime = new TimePopupwindow(getActivity(),
					tv_take);
			takeTime.showPopupWindow(ll_take);
			break;
		case R.id.ll_carTypetext:
			CarTypePopupwindow cartypePop = new CarTypePopupwindow(getActivity(), tv_cartype,null);
			cartypePop.showPopupWindow(ll_cartype);
			break;
		case R.id.ll_addresstext:
			CsdPopupwindow csdPop = new CsdPopupwindow(getActivity(), tv_address, str,null,600);
			csdPop.showList();
			csdPop.showPopupWindow(ll_address);
			break;

		default:
			break;
		}
	}
}
